<?php



/**

 * user actions.

 *

 * @package    mocean_sms

 * @subpackage user

 * @author     Your name here

 * @version    SVN: $Id: actions.class.php 500 2006-01-23 09:15:57Z fabien $

 */

class structureActions extends sfActions

{

  /**

   * Executes index action

   *

   */

  public function executeList()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblStructurePeer::F_LEVEL, "1");
	   	$c->addAnd(TblStructurePeer::F_STATUS, "active");	   	
      	$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
	  	$this->tbl_structures = TblStructurePeer::doSelect($c);
  	}
  }
  
  public function executeFirst()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblStructurePeer::F_LEVEL, "1");
	   	$c->addAnd(TblStructurePeer::F_STATUS, "active");	   	
      	$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
	  	$this->tbl_structures = TblStructurePeer::doSelect($c);
  	}
  }
  
  public function executeFirstedit()
  { 
	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
	 	$this->tbl_structure = $this->getStructureOrCreate();	 	
	}
  }
   
  public function executeFirstupdate()
  { 
	$tbl_structure = $this->getStructureOrCreate();	    
	
	$tbl_structure->setFLevel('1');
	$tbl_structure->setFParentid('0');
	$tbl_structure->setFStatus('active');
	$tbl_structure->setFSeqNo($this->getRequestParameter('f_seq_no'));
	$tbl_structure->setFTitle($this->getRequestParameter('f_title'));
	$tbl_structure->setFName($this->getRequestParameter('f_name'));
	$tbl_structure->setFLink($this->getRequestParameter('f_link'));
	$tbl_structure->setFContentDraft($this->getRequestParameter('content'));
	$tbl_structure->setFMetaKeyword($this->getRequestParameter('f_meta_keyword'));
	$tbl_structure->setFMetaDescription($this->getRequestParameter('f_meta_description'));
	$tbl_structure->setExternalLink($this->getRequestParameter('external_link'));
	if($tbl_structure->getFId()>0){
		$tbl_structure->setFUpdatedDatetime(date('Y-m-d H:i:s'));
		$tbl_structure->setFUpdatedUid($_SESSION['user_id']);
	}else{
		$tbl_structure->setFCreatedDatetime(date('Y-m-d H:i:s'));
		$tbl_structure->setFCreatedUid($_SESSION['user_id']);
	}
	
	if ($this->getRequest()->getFileName('upload_file1') != '') {
		$file_name = strtolower($this->getRequest()->getFileName('upload_file1'));
		$this->getRequest()->moveFile('upload_file1', sfConfig::get('sf_upload_dir')."/".$file_name);

	   	$tbl_structure->setFImageDraft($file_name);
    }
    
    if ($this->getRequest()->getFileName('upload_file2') != '') {
		$file_name = strtolower($this->getRequest()->getFileName('upload_file2'));
		$this->getRequest()->moveFile('upload_file2', sfConfig::get('sf_upload_dir')."/".$file_name);

	   	$tbl_structure->setFIconDraft($file_name);
    }
    
    if ($this->getRequest()->getFileName('upload_file3') != '') {
		$file_name = strtolower($this->getRequest()->getFileName('upload_file3'));
		$this->getRequest()->moveFile('upload_file3', sfConfig::get('sf_upload_dir')."/".$file_name);

	   	$tbl_structure->setHeaderLogo($file_name);
    }
	
    if($this->getRequestParameter('form_action')=="1"){
    	if($tbl_structure->getFImageDraft()<>""){
    		$tbl_structure->setFImage($tbl_structure->getFImageDraft());
    		$tbl_structure->setFImageDraft('');
    	}
    	if($tbl_structure->getFIconDraft()<>""){
    		$tbl_structure->setFIcon($tbl_structure->getFIconDraft());
    		$tbl_structure->setFIconDraft('');
    	}
    	if($tbl_structure->getFContentDraft()<>""){
    		$tbl_structure->setFContent($tbl_structure->getFContentDraft());
    		$tbl_structure->setFContentDraft('');
    	}
    }elseif($this->getRequestParameter('form_action')=="2"){
    	if($tbl_structure->getFImage()<>""){
    		$tbl_structure->setFImageDraft($tbl_structure->getFImage());
    		$tbl_structure->setFImage('');
    	}
    	if($tbl_structure->getFIconDraft()<>""){
    		$tbl_structure->setFIconDraft($tbl_structure->getFIcon());
    		$tbl_structure->setFIcon('');
    	}
    	if($tbl_structure->getFContentDraft()<>""){
    		$tbl_structure->setFContentDraft($tbl_structure->getFContent());
    		$tbl_structure->setFContent('');
    	}
    }
    
    if($this->getRequestParameter('f_image')=="1"){
    	$tbl_structure->setFImage('');
    }
    if($this->getRequestParameter('f_image_draft')=="1"){
    	$tbl_structure->setFImageDraft('');
    }
    
	$tbl_structure->save();
	
	//return $this->redirect('structure/first');
	return $this->redirect('structure/list');
  }
  
  public function executeSecond()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblStructurePeer::F_LEVEL, "1");
	   	$c->addAnd(TblStructurePeer::F_STATUS, "active");
	   	$c->addAscendingOrderByColumn(TblStructurePeer::F_NAME);
	   	//$c->addAscendingOrderByColumn(TblStructurePeer::F_PARENTID);  	
      	//$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
	  	$this->tbl_structures = TblStructurePeer::doSelect($c);
  	}
  }
  
  public function executeSecondedit()
  { 
	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
	 	$this->tbl_structure = $this->getStructureOrCreate();
	 	
	 	$c = new Criteria();
  		$c->add(TblStructurePeer::F_LEVEL, "1");
	   	$c->addAnd(TblStructurePeer::F_STATUS, "active");	   	
      	$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
	  	$this->fstructure = TblStructurePeer::doSelect($c);
	}
  }
   
  public function executeSecondupdate()
  { 
	$tbl_structure = $this->getStructureOrCreate();	    
	
	$tbl_structure->setFLevel('2');
	$tbl_structure->setFParentid($this->getRequestParameter('f_structure'));
	$tbl_structure->setFStatus('active');
	$tbl_structure->setFSeqNo($this->getRequestParameter('f_seq_no'));
	$tbl_structure->setFTitle($this->getRequestParameter('f_title'));
	$tbl_structure->setFName($this->getRequestParameter('f_name'));
	$tbl_structure->setFLink($this->getRequestParameter('f_link'));
	$tbl_structure->setFContentDraft($this->getRequestParameter('content'));
	$tbl_structure->setFMetaKeyword($this->getRequestParameter('f_meta_keyword'));
	$tbl_structure->setFMetaDescription($this->getRequestParameter('f_meta_description'));
	$tbl_structure->setExternalLink($this->getRequestParameter('external_link'));
	$tbl_structure->setChildrenLinkType($this->getRequestParameter('children_link_type'));
	if($tbl_structure->getFId()>0){
		$tbl_structure->setFUpdatedDatetime(date('Y-m-d H:i:s'));
		$tbl_structure->setFUpdatedUid($_SESSION['user_id']);
	}else{
		$tbl_structure->setFCreatedDatetime(date('Y-m-d H:i:s'));
		$tbl_structure->setFCreatedUid($_SESSION['user_id']);
	}
	
	if ($this->getRequest()->getFileName('upload_file1') != '') {
		$file_name = strtolower($this->getRequest()->getFileName('upload_file1'));
		$this->getRequest()->moveFile('upload_file1', sfConfig::get('sf_upload_dir')."/".$file_name);

	   	$tbl_structure->setFImageDraft($file_name);
    }
    
    if ($this->getRequest()->getFileName('upload_file2') != '') {
		$file_name = strtolower($this->getRequest()->getFileName('upload_file2'));
		$this->getRequest()->moveFile('upload_file2', sfConfig::get('sf_upload_dir')."/".$file_name);

	   	$tbl_structure->setFIconDraft($file_name);
    }
    
    if ($this->getRequest()->getFileName('upload_file3') != '') {
		$file_name = strtolower($this->getRequest()->getFileName('upload_file3'));
		$this->getRequest()->moveFile('upload_file3', sfConfig::get('sf_upload_dir')."/".$file_name);

	   	$tbl_structure->setFMenuIcon($file_name);
    }
	
    if($this->getRequestParameter('form_action')=="1"){
    	if($tbl_structure->getFImageDraft()<>""){
    		$tbl_structure->setFImage($tbl_structure->getFImageDraft());
    		$tbl_structure->setFImageDraft('');
    	}
    	if($tbl_structure->getFIconDraft()<>""){
    		$tbl_structure->setFIcon($tbl_structure->getFIconDraft());
    		$tbl_structure->setFIconDraft('');
    	}
    	if($tbl_structure->getFContentDraft()<>""){
    		$tbl_structure->setFContent($tbl_structure->getFContentDraft());
    		$tbl_structure->setFContentDraft('');
    	}
    }elseif($this->getRequestParameter('form_action')=="2"){
    	if($tbl_structure->getFImage()<>""){
    		$tbl_structure->setFImageDraft($tbl_structure->getFImage());
    		$tbl_structure->setFImage('');
    	}
    	if($tbl_structure->getFIconDraft()<>""){
    		$tbl_structure->setFIconDraft($tbl_structure->getFIcon());
    		$tbl_structure->setFIcon('');
    	}
    	if($tbl_structure->getFContentDraft()<>""){
    		$tbl_structure->setFContentDraft($tbl_structure->getFContent());
    		$tbl_structure->setFContent('');
    	}
    }
    
    if($this->getRequestParameter('f_image')=="1"){
    	$tbl_structure->setFImage('');
    }
    if($this->getRequestParameter('f_image_draft')=="1"){
    	$tbl_structure->setFImageDraft('');
    }
    
	$tbl_structure->save();
	
	//return $this->redirect('structure/second');
	return $this->redirect('structure/list');
  }
  
  public function executeThird()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblStructurePeer::F_LEVEL, "1");
	   	$c->addAnd(TblStructurePeer::F_STATUS, "active");
	   	$c->addAscendingOrderByColumn(TblStructurePeer::F_NAME);
	   	//$c->addAscendingOrderByColumn(TblStructurePeer::F_PARENTID);  	
      	//$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
	  	$this->tbl_structures = TblStructurePeer::doSelect($c);
  	}
  }
  
  public function executeThirdedit()
  { 
	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
	 	$this->structure_arr = array();
		$c = new Criteria();
		$c->add(TblStructurePeer::F_LEVEL,'1');
		$c->addAnd(TblStructurePeer::F_STATUS,'active');
		$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
		$first_structure=TblStructurePeer::doSelect($c);
		if($first_structure){			
			foreach($first_structure as $first)
			{
				$avail = false;
				$value = $first->getFName();
				
				$c = new Criteria();
				$c->add(TblStructurePeer::F_LEVEL,'2');
				$c->addAnd(TblStructurePeer::F_STATUS,'active');
				$c->add(TblStructurePeer::F_PARENTID,$first->getFId());
				$second_structure=TblStructurePeer::doSelect($c);
				
				if($second_structure){
					$first_structure = true;
					foreach($second_structure as $second)
					{					
						$avail = true;
						
						if($first_structure==true){
							$value .= "::".$second->getFId()."=".$second->getFName();
							$first_structure=false;
						}else{							
							$value .= ":".$second->getFId()."=".$second->getFName();
						}						
					}
				}
				
				if($avail==true)
					array_push($this->structure_arr,$value);
			}
		}
	 		 	
	 	$this->tbl_structure = $this->getStructureOrCreate();
	 	
	 	if (!$this->getRequestParameter('f_id', 0))
	    {
	      $this->first_structure = 0;
	      $this->second_structure = 0;
	    }
	    else
	    {
	      $third = TblStructurePeer::retrieveByPk($this->getRequestParameter('f_id'));
		  $second = TblStructurePeer::retrieveByPk($third->getFParentid());
		  $first = TblStructurePeer::retrieveByPk($second->getFParentid());
	      $this->old_first_structure = $first->getFName();
	      $this->old_second_structure = $second->getFName();
		
		  $c = new Criteria();
		  $c->add(TblStructurePeer::F_LEVEL,'2');
		  $c->addAnd(TblStructurePeer::F_STATUS,'active');
		  $c->addAnd(TblStructurePeer::F_PARENTID,$first->getFId());
		  $c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
		  $this->sstructure=TblStructurePeer::doSelect($c);
	    }
	    
	 	$c = new Criteria();
  		$c->add(TblStructurePeer::F_LEVEL, "1");
	   	$c->addAnd(TblStructurePeer::F_STATUS, "active");	   	
      	$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
	  	$this->fstructure = $first_structure;	  	
	}
  }
   
  public function executeThirdupdate()
  { 
	$tbl_structure = $this->getStructureOrCreate();	    
	
	$tbl_structure->setFLevel('3');
	$tbl_structure->setFParentid($this->getRequestParameter('f_structure'));
	$tbl_structure->setFStatus('active');
	$tbl_structure->setFSeqNo($this->getRequestParameter('f_seq_no'));
	$tbl_structure->setFTitle($this->getRequestParameter('f_title'));
	$tbl_structure->setFName($this->getRequestParameter('f_name'));
	$tbl_structure->setFLink($this->getRequestParameter('f_link'));
	$tbl_structure->setFContentDraft($this->getRequestParameter('content'));
	$tbl_structure->setFMetaKeyword($this->getRequestParameter('f_meta_keyword'));
	$tbl_structure->setFMetaDescription($this->getRequestParameter('f_meta_description'));
	$tbl_structure->setExternalLink($this->getRequestParameter('external_link'));
	$tbl_structure->setChildrenLinkType($this->getRequestParameter('children_link_type'));
	if($tbl_structure->getFId()>0){
		$tbl_structure->setFUpdatedDatetime(date('Y-m-d H:i:s'));
		$tbl_structure->setFUpdatedUid($_SESSION['user_id']);
	}else{
		$tbl_structure->setFCreatedDatetime(date('Y-m-d H:i:s'));
		$tbl_structure->setFCreatedUid($_SESSION['user_id']);
	}
		
	if ($this->getRequest()->getFileName('upload_file1') != '') {
		$file_name = strtolower($this->getRequest()->getFileName('upload_file1'));
		$this->getRequest()->moveFile('upload_file1', sfConfig::get('sf_upload_dir')."/".$file_name);

	   	$tbl_structure->setFImageDraft($file_name);
    }
    
    if($this->getRequestParameter('form_action')=="1"){
    	if($tbl_structure->getFImageDraft()<>""){
    		$tbl_structure->setFImage($tbl_structure->getFImageDraft());
    		$tbl_structure->setFImageDraft('');
    	}
    	if($tbl_structure->getFContentDraft()<>""){
    		$tbl_structure->setFContent($tbl_structure->getFContentDraft());
    		$tbl_structure->setFContentDraft('');
    	}
    }elseif($this->getRequestParameter('form_action')=="2"){
    	if($tbl_structure->getFImage()<>""){
    		$tbl_structure->setFImageDraft($tbl_structure->getFImage());
    		$tbl_structure->setFImage('');
    	}
    	if($tbl_structure->getFIconDraft()<>""){
    		$tbl_structure->setFIconDraft($tbl_structure->getFIcon());
    		$tbl_structure->setFIcon('');
    	}
    	if($tbl_structure->getFContentDraft()<>""){
    		$tbl_structure->setFContentDraft($tbl_structure->getFContent());
    		$tbl_structure->setFContent('');
    	}
    }
    
    if($this->getRequestParameter('f_image')=="1"){
    	$tbl_structure->setFImage('');
    }
    if($this->getRequestParameter('f_image_draft')=="1"){
    	$tbl_structure->setFImageDraft('');
    }
    
	$tbl_structure->save();
	
	//return $this->redirect('structure/third');
	return $this->redirect('structure/list');
  }
  
  public function executeFourth()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblStructurePeer::F_LEVEL, "1");
	   	$c->addAnd(TblStructurePeer::F_STATUS, "active");
	   	$c->addAscendingOrderByColumn(TblStructurePeer::F_NAME);
	   	//$c->addAscendingOrderByColumn(TblStructurePeer::F_PARENTID);  	
      	//$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
	  	$this->tbl_structures = TblStructurePeer::doSelect($c);
  	}
  }
  
  public function executeFourthedit()
  {
	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
	 	$this->structure_arr = array();
		$c = new Criteria();
		$c->add(TblStructurePeer::F_LEVEL,'1');
		$c->addAnd(TblStructurePeer::F_STATUS,'active');
		$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
		$first_structure=TblStructurePeer::doSelect($c);
		if($first_structure){			
			foreach($first_structure as $first)
			{
				$avail = false;
				$value = $first->getFName();
				
				$c = new Criteria();
				$c->add(TblStructurePeer::F_LEVEL,'2');
				$c->addAnd(TblStructurePeer::F_STATUS,'active');
				$c->add(TblStructurePeer::F_PARENTID,$first->getFId());
				$second_structure=TblStructurePeer::doSelect($c);
				
				if($second_structure){
					$is_first_structure = true;
					foreach($second_structure as $second)
					{					
						$c = new Criteria();
						$c->add(TblStructurePeer::F_LEVEL,'3');
						$c->addAnd(TblStructurePeer::F_STATUS,'active');
						$c->add(TblStructurePeer::F_PARENTID,$second->getFId());
						$third_structure=TblStructurePeer::doSelect($c);
						
						if($third_structure){
							if($is_first_structure==true){
								$value .= "::".$second->getFName();
								$is_first_structure=false;
							}else{							
								$value .= ":".$second->getFName();
							}
							
							$is_second_structure = true;
							foreach($third_structure as $third)
							{						
								$avail = true;								
								if($is_second_structure==true){
									$value .= ";;".$third->getFId()."+".$third->getFName();
									$is_second_structure=false;
								}else{							
									$value .= ";".$third->getFId()."+".$third->getFName();
								}
							}
						}				
					}
				}
				
				if($avail==true)
					array_push($this->structure_arr,$value);
			}
		}
	 		 	
	 	$this->tbl_structure = $this->getStructureOrCreate();
	 	
	 	if (!$this->getRequestParameter('f_id', 0))
	    {
	      $this->first_structure = 0;
	      $this->second_structure = 0;
	      $this->third_structure = 0;
	    }
	    else
	    {
	      $fourth = TblStructurePeer::retrieveByPk($this->getRequestParameter('f_id'));
	      $third = TblStructurePeer::retrieveByPk($fourth->getFParentid());
		  $second = TblStructurePeer::retrieveByPk($third->getFParentid());
		  $first = TblStructurePeer::retrieveByPk($second->getFParentid());
	      $this->old_first_structure = $first->getFName();
	      $this->old_second_structure = $second->getFName();
	      $this->old_third_structure = $third->getFName();
		
		  $c = new Criteria();
		  $c->add(TblStructurePeer::F_LEVEL,'2');
		  $c->addAnd(TblStructurePeer::F_STATUS,'active');
		  $c->addAnd(TblStructurePeer::F_PARENTID,$first->getFId());
		  $c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
		  $this->sstructure=TblStructurePeer::doSelect($c);
		  
		  $c = new Criteria();
		  $c->add(TblStructurePeer::F_LEVEL,'3');
		  $c->addAnd(TblStructurePeer::F_STATUS,'active');
		  $c->addAnd(TblStructurePeer::F_PARENTID,$second->getFId());
		  $c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
		  $this->ssstructure=TblStructurePeer::doSelect($c);
	    }
	    
	 	$c = new Criteria();
  		$c->add(TblStructurePeer::F_LEVEL, "1");
	   	$c->addAnd(TblStructurePeer::F_STATUS, "active");	   	
      	$c->addAscendingOrderByColumn(TblStructurePeer::F_SEQ_NO);
	  	$this->fstructure = $first_structure;  	
	}
  }
   
  public function executeFourthupdate()
  { 
	$tbl_structure = $this->getStructureOrCreate();	    
	
	$tbl_structure->setFLevel('4');
	$tbl_structure->setFParentid($this->getRequestParameter('f_structure2'));
	$tbl_structure->setFStatus('active');
	$tbl_structure->setFSeqNo($this->getRequestParameter('f_seq_no'));
	$tbl_structure->setFTitle($this->getRequestParameter('f_title'));
	$tbl_structure->setFName($this->getRequestParameter('f_name'));
	$tbl_structure->setFLink($this->getRequestParameter('f_link'));
	$tbl_structure->setFContentDraft($this->getRequestParameter('content'));
	$tbl_structure->setFMetaKeyword($this->getRequestParameter('f_meta_keyword'));
	$tbl_structure->setFMetaDescription($this->getRequestParameter('f_meta_description'));
	$tbl_structure->setExternalLink($this->getRequestParameter('external_link'));
	$tbl_structure->setChildrenLinkType($this->getRequestParameter('children_link_type'));
	if($tbl_structure->getFId()>0){
		$tbl_structure->setFUpdatedDatetime(date('Y-m-d H:i:s'));
		$tbl_structure->setFUpdatedUid($_SESSION['user_id']);
	}else{
		$tbl_structure->setFCreatedDatetime(date('Y-m-d H:i:s'));
		$tbl_structure->setFCreatedUid($_SESSION['user_id']);
	}
	
	if ($this->getRequest()->getFileName('upload_file1') != '') {
		$file_name = strtolower($this->getRequest()->getFileName('upload_file1'));
		$this->getRequest()->moveFile('upload_file1', sfConfig::get('sf_upload_dir')."/".$file_name);

	   	$tbl_structure->setFImageDraft($file_name);
    }
    
    if($this->getRequestParameter('form_action')=="1"){
    	if($tbl_structure->getFImageDraft()<>""){
    		$tbl_structure->setFImage($tbl_structure->getFImageDraft());
    		$tbl_structure->setFImageDraft('');
    	}
    	if($tbl_structure->getFContentDraft()<>""){
    		$tbl_structure->setFContent($tbl_structure->getFContentDraft());
    		$tbl_structure->setFContentDraft('');
    	}
    }elseif($this->getRequestParameter('form_action')=="2"){
    	if($tbl_structure->getFImage()<>""){
    		$tbl_structure->setFImageDraft($tbl_structure->getFImage());
    		$tbl_structure->setFImage('');
    	}
    	if($tbl_structure->getFIconDraft()<>""){
    		$tbl_structure->setFIconDraft($tbl_structure->getFIcon());
    		$tbl_structure->setFIcon('');
    	}
    	if($tbl_structure->getFContentDraft()<>""){
    		$tbl_structure->setFContentDraft($tbl_structure->getFContent());
    		$tbl_structure->setFContent('');
    	}
    }
    
    if($this->getRequestParameter('f_image')=="1"){
    	$tbl_structure->setFImage('');
    }
    if($this->getRequestParameter('f_image_draft')=="1"){
    	$tbl_structure->setFImageDraft('');
    }
    
	$tbl_structure->save();
	
	//return $this->redirect('structure/fourth');
	return $this->redirect('structure/list');
  }
  
  public function executeDelete ()
  { 
	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
	 	$tbl_structure = $this->getStructureOrCreate();
	 	$tbl_structure->setFStatus('deleted');
	 	$tbl_structure->setFUpdatedDatetime(date('Y-m-d H:i:s'));
		$tbl_structure->setFUpdatedUid($_SESSION['user_id']);
	 	$tbl_structure->save();
	 	
	 	return $this->redirect('structure/list');
	 	/*if($this->getRequestParameter('f_structure')==1){
	 		return $this->redirect('structure/first?message=The selected structure is deleted!');
	 	}elseif($this->getRequestParameter('f_structure')==2){
	 		return $this->redirect('structure/second?message=The selected structure is deleted!');
	 	}elseif($this->getRequestParameter('f_structure')==3){
	 		return $this->redirect('structure/third?message=The selected structure is deleted!');
	 	}*/	 	
	}
  }
  
  private function getStructureOrCreate ($id = 'f_id')
  {
	if (!$this->getRequestParameter($id, 0))
    {
      $tbl_structure = new TblStructure();
    }
    else
    {
      $tbl_structure = TblStructurePeer::retrieveByPk($this->getRequestParameter($id));
      $this->forward404Unless($tbl_structure instanceof TblStructure);
    }
    return $tbl_structure;
  }
  
  public function executeSitelist()
  {
  	if($_SESSION['user_type']!="System"){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
	  	$c->add(TblSitePeer::F_DELETE, '0');
	  	if($this->getRequestParameter('cbo_search')>0){
	  		if($this->getRequestParameter('cbo_search')==1)
		  		$c->addAnd(TblSitePeer::F_SITE_NO, '%'.$this->getRequestParameter('txt_search').'%', Criteria::LIKE);
		  	elseif($this->getRequestParameter('cbo_search')==2)
		  		$c->addAnd(TblSitePeer::F_SITE_LOCATION, '%'.$this->getRequestParameter('txt_search').'%', Criteria::LIKE);	  	
		  	elseif($this->getRequestParameter('cbo_search')==3)
		  		$c->addAnd(TblSitePeer::F_DISPLAY_SIZE, '%'.$this->getRequestParameter('txt_search').'%', Criteria::LIKE);
		  	
		  	$this->txt_search = $this->getRequestParameter('txt_search');
		  	$this->cbo_search = $this->getRequestParameter('cbo_search');
		  	$this->condition .= '&cbo_search='.$this->getRequestParameter('cbo_search').'&txt_search='.$this->getRequestParameter('txt_search');
	  	}
	  
	  	if($this->getRequestParameter('cbo_order')=='desc'){
		  	$c->addDescendingOrderByColumn(TblSitePeer::F_SITE_NO);
	  	}else{
	  		$c->addAscendingOrderByColumn(TblSitePeer::F_SITE_NO);
	  	}  	
	  	$this->cbo_order = $this->getRequestParameter('cbo_order');
	  	$this->condition .= '&cbo_order='.$this->getRequestParameter('cbo_order');
	  	 
	 	$pager = new sfPropelPager('TblSite', 20);
		$pager->setCriteria($c);
		$pager->setPage($this->getRequestParameter('page', 1));
		$pager->init();
		$this->pager = $pager;
	  	
	  	$this->message = $this->getRequestParameter('message');
  	}
  }
  
  public function executeEditsite ()
  { 
	if($_SESSION['user_type']!="System"){
  		$this->redirect('@homepage');
  	}else{
	 	$this->tbl_site =  $this->getSiteOrCreate();
	 	
	 	$c = new Criteria();
	 	if($this->tbl_site->getFId()>0){
	 		$c->add(TblSitePeer::F_ID, $this->tbl_site->getFId(), Criteria::NOT_EQUAL);
	 	}
	 	$tbl_sites = TblSitePeer::doSelect($c);
	 	
	 	$this->avail_site = "";
	 	foreach ($tbl_sites as $site){
	 		if($this->avail_site=="")
	 			$this->avail_site = $site->getFSiteNo();
	 		else
	 			$this->avail_site .= ";".$site->getFSiteNo();
	 	}
	}
  }
  
  public function executeUpdatesite ()
  {    
	$tbl_site = $this->getSiteOrCreate();
	$tbl_site->setFSiteNo($this->getRequestParameter('f_site_no'));
	$tbl_site->setFSiteLocation($this->getRequestParameter('f_site_location'));
	$tbl_site->setFDisplaySize($this->getRequestParameter('f_display_size'));    
	$tbl_site->save();
		
	return $this->redirect('user/sitelist');	
  }
  
  public function executeCss()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$this->handle = @fopen(realpath(sfConfig::get('sf_root_dir'))."/web/css/main.css", "r");  		
  	}
  }
  
  public function executeCssupdate()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$handle = @fopen(realpath(sfConfig::get('sf_root_dir'))."/web/css/main.css", "w"); 
  		
  		if($handle) {  
			fwrite($handle, $this->getRequestParameter('f_content'));  
          	fclose($handle);  
        }
        
        return $this->redirect('user/main');	
  	}
  }
  
  public function executeGanalytic()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblSettingPeer::F_PARAMETER, 'google analytic');
  		$this->tbl_setting = TblSettingPeer::doSelectOne($c);
  	}
  }
  
  public function executeGanalyticupdate()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblSettingPeer::F_PARAMETER, 'google analytic');
  		$tbl_setting = TblSettingPeer::doSelectOne($c);
        $tbl_setting->setFValue($this->getRequestParameter('f_value'));
        $tbl_setting->save();
        
        return $this->redirect('user/main');
  	}
  }
  
  public function executeSharescript()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblSettingPeer::F_PARAMETER, 'share script');
  		$this->tbl_setting = TblSettingPeer::doSelectOne($c);
  	}
  }
  
  public function executeSharescriptupdate()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblSettingPeer::F_PARAMETER, 'share script');
  		$tbl_setting = TblSettingPeer::doSelectOne($c);
        $tbl_setting->setFValue($this->getRequestParameter('f_value'));
        $tbl_setting->save();
        
        return $this->redirect('user/main');
  	}
  }
  
  public function executeLandingtitle()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblSettingPeer::F_PARAMETER, 'title');
  		$this->tbl_setting = TblSettingPeer::doSelectOne($c);
  	}
  }
  
  public function executeLandingtitleupdate()
  {
  	if($_SESSION['user_id']<=0){
  		$this->redirect('@homepage');
  	}else{
  		$c = new Criteria();
  		$c->add(TblSettingPeer::F_PARAMETER, 'title');
  		$tbl_setting = TblSettingPeer::doSelectOne($c);
        $tbl_setting->setFValue($this->getRequestParameter('f_value'));
        $tbl_setting->save();
        
        return $this->redirect('user/main');
  	}
  }
  
  private function getSiteOrCreate ($id = 'f_id')
  {
	if (!$this->getRequestParameter($id, 0))
    {
      $tbl_site = new TblSite();
    }
    else
    {
      $tbl_site = TblSitePeer::retrieveByPk($this->getRequestParameter($id));
      $this->forward404Unless($tbl_site instanceof TblSite);
    }
    return $tbl_site;
  }
}
?>